package com.estronger.shopmanage.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.bean.BeanShuX;
import com.estronger.shopmanage.utils.ConvertUtils;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017-07-26.
 */

public class StringAdapter extends BaseAdapter {

    private ArrayList<BeanShuX.Shux> mList;
    Activity mContext;

    public StringAdapter(Activity context, ArrayList<BeanShuX.Shux> lt) {
        mContext = context;
        mList = lt;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if (mList != null)
            return mList.size();
        else
            return 0;
    }

    @Override
    public BeanShuX.Shux getItem(int position) {
        // TODO Auto-generated method stub
        if (mList == null || mList.size() <= 0)
            return null;
        else
            return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final ViewHoder vh;
        final BeanShuX.Shux sx = mList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.view_text, null);
            vh = new ViewHoder(convertView);
            convertView.setTag(vh);
            try {
                vh.tvfText.setText(ConvertUtils.formatNull(sx.sname));
            }catch (Exception e){}

        } else {
            vh = (ViewHoder) convertView.getTag();
        }
        return convertView;
    }

    public class ViewHoder {
        TextView tvfText;
        LinearLayout llfTextItem;
        public ViewHoder(View view){
            this.tvfText = (TextView) view.findViewById(R.id.tvfText);
            this.llfTextItem = (LinearLayout) view.findViewById(R.id.llfTextItem);
        }
    }
}
